<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Reservation extends MY_Controller {
	
	public function index(){
		$this->load->library('session');
		$uid = $this->session->userdata('userid');
		$this->load->model('reservation_model');
		$data['list'] = $this->reservation_model->reservationList($uid);
		$this->load->view('reservation',$data);
	}
	
	public function reserve($sid,$type){
		$this->load->library('session');
		$uid = $this->session->userdata('userid');
		if($uid){
			$this->load->model('reservation_model');
			$b = $this->reservation_model->reserve($uid,$sid,$type);
			
			if($b){
				$this->sucJson(['msg'=>'预定成功']);
			}else{
				$this->errJson('预定失败'.$b);
			}
		}else{
			$this->showJson('401','预定失败请登录','预定失败请登录');
		}
		
	}
	
	public function reserveSys(){
		$this->load->model('type_model');
		$this->load->model('worker_model');
		$data['type'] = $this->type_model->allType();
		$data['workers'] = $this->worker_model->allWorker();
		//echo "<PRE>";
		//print_r($data);
		//exit();
		$this->load->view('reserve',$data);
	}
	
	public function reserveByUser(){
		$data['type'] = $this->input->get('type');
		$data['worker'] = $this->input->get('worker');
		$data['time'] = $this->input->get('time');
		$this->load->library('session');
		$uid = $this->session->userdata('userid');
		if($uid){
			$this->load->model('reservation_model');
			$data['user'] = $uid;
			$b = $this->reservation_model->reserveByUser($data);
			if($b){
				$this->sucJson(['msg'=>'预定成功']);
			}else{
				$this->errJson('预定失败'.$b);
			}
		}else{
			$this->showJson('401','预定失败请登录','预定失败请登录');
		}
	}
	
}
	
?>